package com.example.demo.T2.util;

import static com.example.demo.T2.util.RangeRandomUtils.rangeRandom;

/**
 * RangeStepRandom..
 *
 *
 * @author Lizhong
 * @date 2020/8/21
 */
public class RangeStepRandom {
    private int num;
    private int begin;
    private int end;
    int step;


    public RangeStepRandom(int num, int begin, int end, int step) {
        this.num = num;
        this.begin = begin;
        this.end = end;
        this.step = step;
    }

    public int getNext() {

        // (end-begin);
        int v = (num - 1) * step;
        if (v > end || num == 0) return -1;
        int waitingTime = rangeRandom(step, end - v);
        end -= waitingTime;
        num--;

        return waitingTime;
    }

    public double getNext02() {
        int i = (end - begin) / (num);
        double i1 = 0;
        i1 = rangeRandom(step, i);
        num--;
        begin += i1;
        return i1;
    }


    public static void main(String[] args) {
        RangeStepRandom rangeStepRandom = new RangeStepRandom(40, 0, 60, 1);
        for (int i = 0; i < 40; i++) {
            double next = rangeStepRandom.getNext02();


            System.out.println(next);
        }
    }
}
